import Vue from 'vue'

window._methods = {
  //防抖
  deBounce(something, delay) {
    if (window.debounceF) clearTimeout(window.debounceF);
    window.debounceF = setTimeout(function () {
      something();
    }, delay);
  },
  mes(mes,t = false,options = false,stay = false) {

    let option  ={message: mes};

    if (t){
      option.type = {
        1:"success",
        2:"warning",
        3:"error",
      }[t];
    }

    if (stay)option.duration = 0;

    if (options)option = Object.assign(option,options);

    Vue.prototype.$message(option);
  },
  notify(mes,t = 0,options = false) {

    let option  ={
      message: mes,
      offset: 100,
    };

    if (t){
      option.type = {
        0:"info",
        1:"success",
        2:"warning",
        3:"error",
      }[t];
    }

    if (options)option = Object.assign(option,options);

    Vue.prototype.$notify(option);
  }
};

_methods.userInfoGet = () => {
  return new Promise(resolve => {
    _ajax.request(`user/${_data.user.id}`, {menuType: 2}).then(v => {
      let val = v.result;
      if (val){
        _data.user.deptId = val.orgID || "";
        _data.user.name = val.linkdoodName;
        _data.user.deptName = val.orgName;
        _data.user.phoneNumber = val.cellphone;
        _data.user.ready = true;
        resolve(true);
      }
    });
  })
};

_methods.ready = ()=>{
  _methods.userInfoGet();
};
